
import { createPromiseDialog } from '@/utils/createPromiseDialog.js';
import loginComponent from '@/views/login/index.vue';
import require from '@/utils/_require';
import { userInfo } from '@/model/index';


const loginDialog = createPromiseDialog(loginComponent)

let visible = false // 描述弹窗是否打开

export let queue = []
export const login = async function (option) {
  try {
    if (visible) return

    visible = true

    await loginDialog({
      // fullscreen: true,
      showClose: false
    })

    if (option?.userInfo) userInfo.load()

    // for (let tack of queue) {
    //   // require(tack.axios) 写法与之前请求脱节，结果无法赋值到结果
    //   tack?.resolve(require(tack.axios))
    // }
    // console.log(queue)
    // queue = []



  } catch (error) {

  }
  visible = false
}

export const loginCallback = async function (response) {
  try {
    const { promise, resolve, reject } = Promise.withResolvers()

    // if (queue.length === 0) {
    //   queue.push({
    //     axios: response.config,
    //     resolve
    //   })

    await login()

    // } else {
    // }

  } catch (error) {

  }

}
